import { createRouter, createWebHashHistory } from "vue-router";
import { staticRoutes } from "@/router/routes/staticRoutes";

function initRouter() {
  return createRouter({
    history: createWebHashHistory(),
    routes: staticRoutes,
    scrollBehavior: () => ({ left: 0, top: 0 }),
  });
}

const router = initRouter();

export function resetRouter() {
  const newRouter = initRouter();
  router.matcher = newRouter.matcher; // the relevant part
}

/**
 * 路由错误回调
 */
router.onError((handler) => {
  console.log("error:", handler);
});

export default router;
